//
//  Preference.swift
//  zhengwutong
//
//  Created by wangshuguan on 16/8/17.
//  Copyright © 2016年 wangshuguan. All rights reserved.
//

import UIKit
extension UserDefaults{
    subscript (key:String)->Any?{
        set{
            if newValue == nil{
                removeObject(forKey: key)
            }else{
                set(newValue, forKey: key)
            }
            synchronize()
        }
        get{
            return object(forKey: key)
        }
    }
}
class Preference: NSObject {
    static let userDefault = UserDefaults.standard
    class var token:String?{
        get{
            return userDefault["token"] as? String ?? ""
        }
        set{
            userDefault["token"] = newValue
        }
    }
    
    class var loadCount:String?{
        get{
            if let c = userDefault["loadCount"] as? String ,!(c.isEmpty) {
                return c
            }
            return "0"
        }
        set{
            userDefault["loadCount"] = newValue ?? "0"
        }
    }
    class var speed:String?{
        get{
            if let c = userDefault["speed"] as? String ,!(c.isEmpty) {
                return c
            }
            return "1"
        }
        set{
            userDefault["speed"] = newValue ?? "1"
        }
    }
    class var background:String?{
        get{
            return userDefault["background"] as? String
        }
        set{
            userDefault["background"] = newValue
        }
    }
    class var textColor:String?{
        get{
            return userDefault["textColor"] as? String
        }
        set{
            userDefault["textColor"] = newValue
        }
    }
}

